// 获取初始设置
$.ajax({
  tpye: 'get',
  url: '/settings',
  success: function (response) {
    console.log(response);
    if(response) {
      $('#img').prop('src', response.logo);
      $('#hiddenLogo').val(response.logo);
      $('#title').val(response.title);
      $('#comment').prop('checked', response.comment);
      $('#review').prop('checked', response.review);
    }
  }
})

$('#logo').on('change', function () {
  const formData = new FormData();
  formData.append('logo', this.files[0]);
  $.ajax({
    type: 'post',
    url: '/upload',
    data: formData,
    contentType: false,
    processData: false,
    success: function (response) {
      $('#hiddenLogo').val(response[0].logo);
      $('#img').prop('src', response[0].logo);
    }
  })
})

// 提交表单
$('#settingsForm').on('submit', function () {
  const formData = $(this).serialize();
  $.ajax({
    type: 'post',
    url: '/settings',
    data: formData,
    success: function () {
      location.reload();
    }
  })
  return false;
})